﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rio.Workflow.Runtime;
using Rio.Workflow.Runtime.Enums;
using NetBay.Core.BusinessEntities.Workflow;
using NetBay.Core.Log;

namespace Rio.Workflow.Common
{
    public class CommonAction : WorkflowActionContext
    {

        /// <summary>
        /// Executes the reject action.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public override ActionResult ActionExecuted(WorkflowContextBase context, ActionRequest request)
        {
            ActionResult result = ActionResult.Faulted;
            try
            {
                if (request.UiActionType == WorkflowTypeAction.Ventilate)
                {
                    this.Ventilate();
                }

                result = ActionResult.Executed;
            }
            catch (Exception ex)
            {
                LogManager.Instance().LogDebugFormat("Execute error - " + ex.Message);
                throw;
            }

            return result;
        }

        /// <summary>
        /// Executes the reject action.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public override ActionResult ActionExecutedAll(WorkflowContextBase context, ActionRequest request)
        {
            ActionResult result = ActionResult.Faulted;
            try
            {
                if (request.UiActionType == WorkflowTypeAction.Ventilate)
                {
                    this.Ventilate();
                }

                result = ActionResult.Executed;
            }
            catch (Exception ex)
            {
                LogManager.Instance().LogDebugFormat("ExecuteAll error - " + ex.Message);
                throw;
            }

            return result;
        }
    }
}
